package tr.edu.yildiz.ce.dap.appagent.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Properties;

public class AgentProperties {
	
	private static String AGENT_NAME = "agent.name";
	private static String AGENT_PORT = "agent.port";
	private static String AGENT_LISTENING_PORT = "agent.listeningPort";
	
	private static String AGENT_MCAST_ADDRESS = "agent.mcast.address";
	private static String AGENT_MCAST_PORT = "agent.mcast.port";
	
	private static String AGENT_TEMP_FOLDER = "agent.temp.folder";
	
	private static String AGENT_ENCODING = "agent.encoding";
	private static String AGENT_UNINSTALL_WHEN_OFFLINE = "agent.uninstallWhenOffline";
	
	private static String AGENT_PROMPT =  "agent.prompt";
	private static String AGENT_RESOURCES_FOLDER = "agent.resources.folder";
	
	private static AgentProperties instance;
	private Properties properties;
	
	public AgentProperties() {
		properties = new Properties();
		String confPropPath = System.getProperty("conf.properties");
		try {
			if (confPropPath == null){
				properties.load(AgentProperties.class.getResourceAsStream("android.properties"));
			}else {
				properties.load(new FileReader(new File(confPropPath)));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	public static AgentProperties getInstance() {
		if (instance == null)
			instance= new AgentProperties();
		return instance;
	}

	public String getName() {
		return properties.getProperty(AGENT_NAME);
	}

	public int getPort() {
		return Integer.parseInt(properties.getProperty(AGENT_PORT));
	}

	public BigInteger getListeningPort() {
		return new BigInteger(properties.getProperty(AGENT_LISTENING_PORT));
	}

	public String getProxyMcastAddress() {
		return properties.getProperty(AGENT_MCAST_ADDRESS);
	}

	public Integer getProxyPort() {
		return Integer.parseInt(properties.getProperty(AGENT_MCAST_PORT));
	}

	public  String getBundlePath() {
		return properties.getProperty(AGENT_TEMP_FOLDER);
	}
	
	public  String getResourcePath() {
		return properties.getProperty(AGENT_RESOURCES_FOLDER);
	}

	public  String getENCODING() {
		return properties.getProperty(AGENT_ENCODING);
	} 
	
	public boolean isAgentUninstallWhenOffline() {
		String strValue = properties.getProperty(AGENT_UNINSTALL_WHEN_OFFLINE);
		if (strValue == null)
			return false;
		return Boolean.valueOf(strValue);	
	}
	
	public  String getPrompt() {
		return properties.getProperty(AGENT_PROMPT);
	}

}
